package com.nineclock.system.controller;

import com.nineclock.common.entity.Result;
import com.nineclock.system.SysUserControllerApi;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.dto.SysRegisterDTO;
import com.nineclock.system.dto.SysUserDTO;
import com.nineclock.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/user")
public class SysUserController implements SysUserControllerApi {


    @Autowired
    SysUserService userService;


    @Override
    @GetMapping("/query")
    public Result<SysUserDTO> queryUser(String username) {
        SysUserDTO sysUserDTO = userService.queryUser(username);
        return Result.success(sysUserDTO);
    }

    @Override
    @PostMapping("/register")
    public Result register(SysRegisterDTO sysRegisterDTO) {
        Long userId = userService.register(sysRegisterDTO);
        return Result.success(userId);
    }

    @GetMapping("/findById")
    public Result<SysCompanyUserDTO> findById(Long userId){
        SysCompanyUserDTO userDTO = userService.findById(userId);
        return Result.success(userDTO);
    }
}
